package cn.iocoder.yudao.module.call.service.aiqualitytestinglabel;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.call.controller.admin.aiqualitytestinglabel.vo.*;
import cn.iocoder.yudao.module.call.dal.dataobject.aiqualitytestinglabel.AiQualityTestingLabelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.call.dal.mysql.aiqualitytestinglabel.AiQualityTestingLabelMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.call.enums.ErrorCodeConstants.*;

/**
 * 大模型质检标签 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class AiQualityTestingLabelServiceImpl implements AiQualityTestingLabelService {

    @Resource
    private AiQualityTestingLabelMapper aiQualityTestingLabelMapper;

    @Override
    public Long createAiQualityTestingLabel(AiQualityTestingLabelSaveReqVO createReqVO) {
        // 插入
        AiQualityTestingLabelDO aiQualityTestingLabel = BeanUtils.toBean(createReqVO, AiQualityTestingLabelDO.class);
        aiQualityTestingLabelMapper.insert(aiQualityTestingLabel);
        // 返回
        return aiQualityTestingLabel.getId();
    }

    @Override
    public void updateAiQualityTestingLabel(AiQualityTestingLabelSaveReqVO updateReqVO) {
        // 校验存在
        validateAiQualityTestingLabelExists(updateReqVO.getId());
        // 更新
        AiQualityTestingLabelDO updateObj = BeanUtils.toBean(updateReqVO, AiQualityTestingLabelDO.class);
        aiQualityTestingLabelMapper.updateById(updateObj);
    }

    @Override
    public void deleteAiQualityTestingLabel(Long id) {
        // 校验存在
        validateAiQualityTestingLabelExists(id);
        // 删除
        aiQualityTestingLabelMapper.deleteById(id);
    }

    private void validateAiQualityTestingLabelExists(Long id) {
        if (aiQualityTestingLabelMapper.selectById(id) == null) {
            throw exception(AI_QUALITY_TESTING_LABEL_NOT_EXISTS);
        }
    }

    @Override
    public AiQualityTestingLabelDO getAiQualityTestingLabel(Long id) {
        return aiQualityTestingLabelMapper.selectById(id);
    }

    @Override
    public PageResult<AiQualityTestingLabelDO> getAiQualityTestingLabelPage(AiQualityTestingLabelPageReqVO pageReqVO) {
        return aiQualityTestingLabelMapper.selectPage(pageReqVO);
    }

}